package com.how2java.springboot.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.how2java.springboot.mapper.CategoryMapper;
import com.how2java.springboot.pojo.Category;
import com.how2java.springboot.service.ICategory;

/**
 * 有关事务的延伸
 * 	直接在数据库中测试事务嵌套这种情况
 * 	测试下不同种类的事务传播模式，尤其是在service层调用的情况
 * @author Administrator
 *
 */
@Transactional
@Service
public class CategoryBO implements ICategory{

    @Autowired CategoryMapper categoryMapper;
    
	@Override
	public List<Category> findAll() {
		return categoryMapper.findAll();
	}

	//https://www.cnblogs.com/sllina/p/5694805.html	具体使用
	//https://my.oschina.net/happyBKs/blog/1624482	为什么不起作用!!!
//	@Transactional(propagation = Propagation.NOT_SUPPORTED )  简单测试如果当前存在事务，取消事务
	@Override
	public void addCategory() {
		Category c=new Category();
		c.setName("test");
		categoryMapper.addCategory(c);
		int i=1/0;
		Category c1=new Category();
		c1.setName("test222");
		categoryMapper.addCategory(c1);
		
	}

}
